package com.xjh.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xjh.po.StudentPO;
import com.xjh.service.StudentService;
import com.xjh.utils.exception.BaseException;
import com.xjh.utils.exception.MessageException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import com.xjh.mapper.TestTableMapper;
import com.xjh.bo.TestTable;
import com.xjh.service.TestTableService;

/**
 * @author： 徐建华
 * @date： 2022/5/22
 * @description：
 */
@Service
public class TestTableServiceImpl extends ServiceImpl<TestTableMapper, TestTable> implements TestTableService {

    @Resource
    private TestTableMapper testTableMapper;

    @Autowired
    private StudentService studentService;



    @Override
    public int deleteByPrimaryKey(Integer id) {
        return testTableMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(TestTable record) {
        return testTableMapper.insert(record);
    }

    @Override
    public int insertSelective(TestTable record) {
        return testTableMapper.insertSelective(record);
    }

    @Override
    public TestTable selectByPrimaryKey(Integer id) {
        return testTableMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(TestTable record) {
        return testTableMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(TestTable record) {

        List<TestTable> testTables = testTableMapper
                .selectList(Wrappers.<TestTable>lambdaQuery()
                        .select(TestTable::getMoney)
                        .eq(TestTable::getStuId, 212L)

                );
        studentService.getOne(Wrappers.lambdaQuery());
        // impl多了一些批处理的方法,且不用写service.;
        // 加这个泛型是为了后面可以用双冒号
        getOne(Wrappers.<TestTable>lambdaQuery().eq(TestTable::getId, 212L));

        // 直接lambdaQuery 不加wapper
        studentService.lambdaQuery().eq(StudentPO::getId,123L).oneOpt().orElseThrow(() -> new MessageException("检测计划不存在"));

        getOne(Wrappers.<TestTable>lambdaQuery()
                .eq(TestTable::getId, 212L)
        );

        return testTableMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<TestTable> selectAllByStuId(Integer stuId) {
        return testTableMapper.selectAllByStuId(stuId);
    }


}
